from __future__ import division
from operator import itemgetter, attrgetter

import gc
import math
import matplotlib
import os
import pylab
import random
import sys
import time
from sets import Set
from scipy import stats
import numpy as np

print "Program Begins..."
top10PostingForHumanJudgedQueryDict = {}
outputFileName = "/home/diaosi/workspace/web-search-engine-wei-2014-March/polyIRIndexer/humanJudgeQueryResults_AND_POSTINGS_20140302Afternoon"
outputFileHandler = open(outputFileName,"w")

inputFileName = "/home/diaosi/web-search-engine-wei_MOVE_FROM_PANGOLIN_20131206/polyIRIndexer/2014JanPruningResults/reproduceRomanQueryEffectiveness_20140121Night/qrels.tb04-tb06.top150_with_docID_added_termid_added"
inputFileHandler = open(inputFileName,"r")

for index,line in enumerate( inputFileHandler.readlines() ):
    lineElements = line.strip().split(" ")
    currentQID = lineElements[0]
    currentTrecID = lineElements[2]
    relevanceLabel = lineElements[3]
    currentDocID = lineElements[4]
    if relevanceLabel != "0":
        for currentTermID in lineElements[5:]:
            currentPostingKey = currentTermID + "_" + currentDocID
            if currentPostingKey not in top10PostingForHumanJudgedQueryDict:
                top10PostingForHumanJudgedQueryDict[currentPostingKey] = 1
            else:
                top10PostingForHumanJudgedQueryDict[currentPostingKey] += 1
            outputFileHandler.write(currentQID + " " + currentTrecID + " " + currentDocID + " " + currentTermID + " " + "N/A" + "\n")
    # if index == 1:
    #     break
print "Overall:"
print "len(top10PostingForHumanJudgedQueryDict):",len(top10PostingForHumanJudgedQueryDict)
# print "top10PostingForHumanJudgedQueryDict:",top10PostingForHumanJudgedQueryDict
print "inputFileName:",inputFileName
print "outputFileName:",outputFileName
inputFileHandler.close()
outputFileHandler.close()
print "Program Ends."
exit(1)





